﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 养老金支付系统
{
    public partial class FormGRZFMXCX : FormBase
    {
        public FormGRZFMXCX()
        {
            InitializeComponent();
        }

        string grbh = string.Empty;

        const string sql = @"select 支付期号,个人编号,姓名,身份证号,支付类型,支付金额,银行名称,
银行户名,银行帐号,备注,交易状态,失败原因,补发状态,补发期号
from 查支付明细 where 个人编号=@GRBH order by 支付编号 desc";

        void buttonEnabled(bool b)
        {
            buttonGRBH.Enabled = b;
            button1.Enabled = b;
            button2.Enabled = b;
            button3.Enabled = b;
        }

        void init()
        {
            this.Text = "个人支付明细查询";
        }

        void find()
        {
            if (this.grbh.Length == 10)
                dataGridView1.DataSource = SqlHelper.getDataTable(sql, new SqlParameter("@GRBH", this.grbh));
        }

        void output()
        {
            DataTable dt = dataGridView1.DataSource as DataTable;
            if (dt != null)
            {
                SaveFileDialog sfd = new SaveFileDialog() { Title = "导出", FileName = textBox1.Text + "的支付明细", Filter = "Excel(97-2003)|*.xls" };
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    ExcelHelper.DataTableToExcel(dt, sfd.FileName);
                }
            }
        }

        void print()
        {
            DataTable dt = dataGridView1.DataSource as DataTable;
            if (dt != null)
            {
                FormPrintView fpv = new FormPrintView()
                {
                    ReportDataSetName = "支付明细",
                    DataSources = dataGridView1.DataSource,
                    ReportPath = "ZFMX.rdlc"
                };
                fpv.ShowDialog();
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.grbh = textBox1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            buttonEnabled(false);
            find();
            buttonEnabled(true);
        }

        private void buttonGRBH_Click(object sender, EventArgs e)
        {
            buttonEnabled(false);
            FormGRBHXZ fgrbhxz = new FormGRBHXZ();
            if (fgrbhxz.ShowDialog() == DialogResult.OK)
            {
                this.grbh = fgrbhxz.GRBH;
                textBox1.Text = this.grbh;
                find();
            }
            buttonEnabled(true);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            buttonEnabled(false);
            output();
            buttonEnabled(true);
        }

        private void FormGRZFMXCX_Load(object sender, EventArgs e)
        {
            init();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            buttonEnabled(false);
            print();
            buttonEnabled(true);
        }


    }
}
